﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using LCA.Security;
using LCA.Utils;

public partial class Frontend_Controls_ProfileBox : System.Web.UI.UserControl
{
    protected void Page_Load(object sender, EventArgs e)
    {
        RefreshComponents();
    }

    protected override void OnInit(EventArgs e)
    {
        base.OnInit(e);

        DisableClientCaching();
    }

    private void DisableClientCaching()
    {
        // Stop Caching in IE
        Response.Cache.SetCacheability(System.Web.HttpCacheability.NoCache);

        // Stop Caching in Firefox
        Response.Cache.SetNoStore();
    }

    public void RefreshComponents()
    {
        plhLoggedIn.Visible = false;
        plhNotLoggedIn.Visible = false;

        if (LCAAuthentication.IsLoggedIn())
        {
            plhLoggedIn.Visible = true;
            lnkProfile.Text = LCAAuthentication.GetUsername();
        }
        else
        {
            plhNotLoggedIn.Visible = true;
        }
    }

    protected void lnkLogout_Click(object sender, EventArgs e)
    {
        LCAAuthentication.Logout();
        PageHelper.ClientPageRedirect(LCAAuthentication.HomePageId);
    }
}